<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-pet__petlost}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.petName" placeholder="宠物名字" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="imageUrl" label="照片" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.imageUrlSize === 0" size="small" type="danger">暂无图片</el-tag>
            <el-image v-else style="width: 80px; height: 80px" :src="scope.row.imageUrlList[0]"
              :preview-src-list="scope.row.imageUrlList"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="postType" label="发布类型" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.postType === 0" size="small" type="primary">寻找爱宠</el-tag>
            <el-tag v-if="scope.row.postType === 1" size="small" type="success">寻找主人</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petName" label="宠物名字" header-align="center" align="center"></el-table-column>
        <el-table-column prop="petGender" label="性别" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petGender === 0" size="small" type="primary">公</el-tag>
            <el-tag v-if="scope.row.petGender === 1" size="small" type="success">母</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="petBreed" label="宠物品种" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.petBreed === 0" size="small" type="primary">狗狗</el-tag>
            <el-tag v-if="scope.row.petBreed === 1" size="small" type="success">猫猫</el-tag>
            <el-tag v-if="scope.row.petBreed === 2" size="small" type="info">其他</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="丢失信息" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="showConditions(scope.row)">查看信息</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" size="small" type="warning">待审核</el-tag>
            <el-tag v-if="scope.row.status === 1" size="small" type="success">审核通过</el-tag>
            <el-tag v-if="scope.row.status === 2" size="small" type="danger">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="审核" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="examine(scope.row.id, 1)">通过</el-button>
            <el-button type="text" size="small" @click="examine(scope.row.id, 2)">未通过</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
    <el-dialog title="丢失信息" :visible.sync="lostDialogVisible" width="30%">
      <p>丢失地址: {{ showLostData.lostAddress }}</p>
      <p>丢失时间: {{ showLostData.lostTime }}</p>
      <p>所在城市: {{ showLostData.city }}</p>
      <p>联系人姓名: {{ showLostData.contactName }}</p>
      <p>联系人电话: {{ showLostData.contactPhone }}</p>
      <p>微信号: {{ showLostData.contactWechat }}</p>
      <p>宠物描述信息: {{ showLostData.description }}</p>
    </el-dialog>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/pet/petlost/page',
        getDataListIsPage: true,
        deleteURL: '/pet/petlost',
        deleteIsBatch: true
      },
      dataForm: {
        petName: ''
      },
      lostDialogVisible: false,
      showLostData: {}
    }
  },
  components: {
  
  },
  methods: {
    showConditions(item) {
      this.lostDialogVisible = true
      this.showLostData = item
    },
    // 审核接口
    examine(id, status) {
      this.$http
        .put("/pet/petlost", {
          id: id,
          status: status
        })
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.$message({
              message: "审核提交成功！",
              type: "success",
            });
            this.query();
          } else {
            this.$message.error("审核提交失败！");
          }
        });
    }
  }
}
</script>
